package cn.sccdlg.ssm.service.impl;

import cn.sccdlg.ssm.dao.IPermissionDao;
import cn.sccdlg.ssm.domain.Permission;
import cn.sccdlg.ssm.service.PermissionService;
import cn.sccdlg.ssm.utils.UuidUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author RaoShuang
 * @emil 991207823@qq.com
 * @date 2020/10/28 23:23
 * 权限资源业务层实现类
 */
@Service("permissionService")
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private IPermissionDao permissionDao;

    @Override
    public List<Permission> findAll() throws Exception {
        return permissionDao.findAll();
    }

    @Override
    public void save(Permission permission) throws Exception {
        permission.setId(UuidUtils.getUnid());
        permissionDao.save(permission);
    }

    @Override
    public Permission findById(String id) throws Exception {
        return permissionDao.findById(id);
    }

    @Override
    public void deleteById(String id) throws Exception {
        //删除角色与权限资源关联
        permissionDao.deleteFromRole2Permission(id);
        //删除权限资源
        permissionDao.deleteById(id);
    }
}
